<template>
  <a-form :form="form">
    <a-row>
      <a-col :span="12">
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.newsType','新闻类型')">
          <a-select style="width: 80%" defaultValue="img" v-model="newType" @change="defChangeType">
            <a-select-option v-for="item in newsTypeList" :key="item.id" :value="item.id">{{item.text}}
            </a-select-option>
          </a-select>
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.selectNewsType','选择新闻分类')">
          <a-select style="width: 80%" id="newDIc" v-model="newDIc" @change="changeDicType">
            <a-select-option v-for="item in sysDicNewList" :key="item.value" :value="item.value">{{item.name}}
            </a-select-option>
          </a-select>
        </a-form-item>
      </a-col>
    </a-row>
  </a-form>
</template>

<script>
  import {BaseForm, RxDialog} from "@lowcode/jpaas-common-lib";
  import rxAjax from '@/assets/js/ajax.js';
  import InsNewsApi from '@/api/portal/core/insNews';

  export default {
    name: "InsColumnDefNewsBel",
    mixins: [BaseForm],
    components: {
      RxDialog, rxAjax, InsNewsApi
    },
    props: {
      dataObj: {
        type: Object,
        default: null
      }
    },
    data() {
      return {
        newType: "",
        newsTypeList: [
            {
                "text": this.i18n('form.img','图片'),
                "id": "img"
            }, {
                "text": this.i18n('form.wordsList','文字列表'),
                "id": "wordsList"
            }, {
                "text": this.i18n('form.imgAndFont','图片与文件'),
                "id": "imgAndFont"
            }
        ],
        newDIc: "",
        sysDicNewList: []
      }
    },
    created() {
      if (this.dataObj.newType) {
        this.newType = this.dataObj.newType;
      } else {
        this.newType = "img";
      }
      this.newDIc = this.dataObj.newDIc;
      this.sendsNews();
      this.getInsSysDicNewList();
    },
    methods: {
      i18n(name,text,key){
          return this.$ti18(name,text,"insColumnDef",key);
      },
      changeDicType(e) {
        this.newDIc = e;
        this.sendsNews();
      },
      async getInsSysDicNewList() {
          let res= await InsNewsApi.getTopDicByKey()
          this.sysDicNewList= res.data?res.data:[]

          //获取共享数据
          let self=this
          InsNewsApi.getShareDicList().then(data=>{
              data.map(item=>{
                  return self.sysDicNewList.push({name:item.name,value:item.value})
              })
          })
      },
      valid() {
        return true;
      },
      defChangeType(val) {
        this.newType = val;
        this.sendsNews();
      },
      sendsNews() {
        this.dataObj.dataUrl = "/insNewsList";
        this.dataObj.newType = this.newType;
        this.dataObj.newDIc = this.newDIc;
        this.$emit("change", this.dataObj);
      }
    }
  }
</script>

<style scoped>

</style>